package com.niit.TopOne.citytopone;


import com.niit.bean.CityTopOneBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


public class CityTopOneMapper extends Mapper<LongWritable, Text, CityTopOneBean, NullWritable> {

    CityTopOneBean outKey = new CityTopOneBean();
    NullWritable outValue = NullWritable.get();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        String Province = fields[7];
        String City = fields[8];
        long StudentsNum =Long.parseLong(fields[6]);  //学生人数

        if (Province == null || Province.equals("未知") || City == null || City.equals("未知")) {
            return; // 跳过这个记录，不进行处理
        }

        outKey.set(Province,City,StudentsNum);
        context.write(outKey,outValue);
    }

}
